package pl.wr.physics.units.quantum.particleflavour.related;

import pl.wr.math.Sign;
import pl.wr.math.number.Fraction;

/**
 * In particle physics, the baryon number is an approximate conserved quantum
 * number of a system. It is defined as B = 1/3 (nq - naq) where nq is the
 * number of quarks, and naq is the number of antiquarks.
 * 
 * @version 1.0
 * @author wieslaw.rodak
 * 
 */
public final class BaryonNumber {

    public final Fraction baryonNumber;

    /** A baryonNumber representing "1/3". */
    public static final BaryonNumber ONE_THIRD = new BaryonNumber(Fraction.ONE_THIRD);

    /** A baryonNumber representing "-1/3". */
    public static final BaryonNumber MINUS_ONE_THIRD = new BaryonNumber(Fraction.MINUS_ONE_THIRD);

    /** A baryonNumber representing "0". */
    public static final BaryonNumber ZERO = new BaryonNumber(Fraction.ZERO);

    /** A baryonNumber representing "+1". */
    public static final BaryonNumber ONE = new BaryonNumber(Fraction.ONE);

    /** A baryonNumber representing "-1". */
    public static final BaryonNumber MINUS_ONE = new BaryonNumber(Fraction.MINUS_ONE);

    /**
     * @param value
     */
    private BaryonNumber(Fraction value) {
        baryonNumber = value;
    }

    /**
     * @param s
     *            The sign of value.
     * @param multiply
     *            The multiply value of 1/3.
     */
    public BaryonNumber(Sign s, int multiply) {
        switch (s) {
        case minus:
            multiply = -multiply;
        }
        baryonNumber = new Fraction(multiply, 3);
    }

    /**
     * @return The string representation of particle type.
     */
    public String getTypeParticle() {

        if (baryonNumber.isZero()) {
            return "Meson";//TODO a elektron?
        } else if (1 == baryonNumber.doubleValue()) {
            return "Baryon";
        } else if (baryonNumber.doubleValue() == -1) {
            return "AntiBaryon";
        } else {
            return "Quark";
        }
    }

    /**
     * @return <code>true</code> if object is a Baryon.
     */
    public boolean isBaryon() {

        if (1 == Math.abs(baryonNumber.doubleValue())) {
            return true;
        } else {
            return false;
        }
    }

}
